#!/usr/bin/python
#
# Copyright (C) 2008 rambla.be
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

""" Contains the objects required for RASE wowapp resource access. """
try:
  from xml.etree import cElementTree as ElementTree
except ImportError:
  try:
    import cElementTree as ElementTree
  except ImportError:
    from elementtree import ElementTree

import atom
import rawsc
from rawsc import RAWS_NAMESPACE
from rawsc.rase import *

class WowappParams(rawsc.RawsParams):
    _children = {}
    _children['{%s}id' % RAWS_NAMESPACE] = ('id', Id)
    _children['{%s}name' % RAWS_NAMESPACE] = ('name', Name)
    _children['{%s}description' % RAWS_NAMESPACE] = ('description', Description)
    _children['{%s}stream_type' % RAWS_NAMESPACE] = ('stream_type', StreamType)
    _children['{%s}stream_uri' % RAWS_NAMESPACE] = ('stream_uri', StreamUri)
    _children['{%s}master_uri' % RAWS_NAMESPACE] = ('master_uri', MasterUri)
    _children['{%s}broadcast_domain' % RAWS_NAMESPACE] = ('broadcast_domain', BroadcastDomain)
    _children['{%s}broadcast_ip' % RAWS_NAMESPACE] = ('broadcast_ip', BroadcastIp)
    _children['{%s}broadcast_backup_domain' % RAWS_NAMESPACE] = ('broadcast_backup_domain', BroadcastBackupDomain)
    _children['{%s}broadcast_backup_ip' % RAWS_NAMESPACE] = ('broadcast_backup_ip', BroadcastBackupIp)

    def __init__(self, id=None, name=None, description=None, stream_type=None, stream_uri=None, master_uri=None, broadcast_domain=None, broadcast_ip = None, broadcast_backup_domain = None, broadcast_backup_ip = None):
        rawsc.RawsParams.__init__(self, extension_elements=None, extension_attributes=None)
        self.id = Id(text = id)
        self.name = Name(text = name)
        self.description = Description(text = description)
        self.stream_type = StreamType(text = stream_type)
        self.stream_uri = StreamUri(text = stream_uri)
        self.master_uri = MasterUri(text = master_uri)
        self.broadcast_domain = BroadcastDomain(text = broadcast_domain)
        self.broadcast_ip = BroadcastIp(text = broadcast_ip)
        self.broadcast_backup_domain = BroadcastBackupDomain(text = broadcast_backup_domain)
        self.broadcast_backup_ip = BroadcastBackupIp(text = broadcast_backup_ip)

def WowappParamsFromString(xml_string):
    return atom.CreateClassFromXMLString(WowappParams, xml_string)   


class WowappContent(rawsc.RawsContent):
    """The atom:content element"""
    _children = atom.AtomBase._children.copy()
    _children['{%s}params' % (RAWS_NAMESPACE)] = ('params', WowappParams)
    
    params = None
    
    def __init__(self, params=None):
        rawsc.RawsContent.__init__(self, extension_elements=None, extension_attributes=None)
        self.params = Params()
        if params:
            self.params = params
    
def WowappContentFromString(xml_string):
    return atom.CreateClassFromXMLString(WowappContent, xml_string)   
    

class WowappEntry(rawsc.RawsEntry):
    """Represents a RASE wowapp profile."""
    _children = rawsc.RawsEntry._children.copy()
    _children['{%s}content' % atom.ATOM_NAMESPACE] = ('content', WowappContent)

    def __init__(self, author=None, category=None, atom_id=None, link=None, published=None, title=None, updated=None, content = None, extension_elements=None, extension_attributes=None):
        rawsc.RawsEntry.__init__(self, author=author, category=category, atom_id=atom_id, link=link, published=published, title=title, updated=updated,
                                extension_elements=extension_elements, extension_attributes=extension_attributes)
        self.content = WowappContent()
        if content:
            self.content = content

def WowappEntryFromString(xml_string):
    return atom.CreateClassFromXMLString(WowappEntry, xml_string)
    

class WowappFeed(rawsc.RawsFeed, rawsc.LinkFinder):
    """Represents a RASE  feed."""
    _children = rawsc.RawsFeed._children.copy()
    _children['{%s}entry' % atom.ATOM_NAMESPACE] = ('entry', [WowappEntry])

def WowappFeedFromString(xml_string):
  return atom.CreateClassFromXMLString(WowappFeed, xml_string)

